home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11923 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  46 lines

  1. Path: news.gulfaero.com!not-for-mail
  2. From: swofford@voyager.eng.gulfaero.com (Van Swofford)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: string search?
  5. Date: 27 Mar 1996 14:52:46 -0500
  6. Organization: Gulfstream Aerospace Corporation, Savannah Georgia USA
  7. Message-ID: <4jc6ae$eol@voyager.eng.gulfaero.com>
  8. NNTP-Posting-Host: voyager.eng.gulfaero.com
  9.  
  10. Ricardo Mor  <rmor1@ix.netcom.com> wrote:
  11. >    How can I search for a string of characters within another string?
  12. >for example..
  13. >
  14. >    string = "NEXT_TIME";
  15. >    
  16. >    string2 = "NEXT";
  17. >
  18. >    how can I find  string2 in string?
  19. >
  20. >
  21. >Eddy...
  22.  
  23.  
  24. Try:
  25.  
  26. #include <string.h>
  27.  
  28. char string[] = "NEXT_TIME";
  29. char string2[] = "NEXT";
  30. char *ptr;
  31. int  position;
  32.  
  33. ptr = strstr (string, string2);
  34. position = ptr - string;        /* first char position in string would be 0 */
  35.  
  36. The Microsoft C documentation indicates that strstr is ANSI compliant,
  37. but not available under UNIX.
  38.  
  39. Hope this helps.
  40. Van
  41. -- 
  42.  
  43. ______________________________________________________________________________
  44. "Half of what I say is meaningless....." - John Lennon
  45. Your job, should you choose to accept it, is to determine which half.
  46.